package swing.customComp;

import javax.swing.*;

/**
 * 自定义控件：带默认提示的输入框
 */
public class HintJTextField extends JTextField {

    //当前是否为默认提示内容
    private boolean hint = false;

    protected String hintText = "";

    public void setHintText(String hintText) {
        this.hint = true;
        this.hintText = hintText;
        addFocusListener(new JTextFieldHintListener(this, hintText));
    }

    @Override
    public String getText() {
        return isHint() ? "" : super.getText();
    }

    protected String getRealText() {
        return super.getText();
    }

    protected boolean isHint() {
        return hint;
    }

    protected void setHint(boolean hint) {
        this.hint = hint;
    }

}
